package org.jeecg.modules.tls.csmg.csanswerlike.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.jeecg.modules.tls.csmg.csanswerlike.entity.CsAnswerLike;
import org.jeecg.modules.tls.csmg.csanswerlike.mapper.CsAnswerLikeMapper;
import org.jeecg.modules.tls.csmg.csanswerlike.service.ICsAnswerLikeService;
import org.jeecg.modules.tls.csmg.viewmodel.qa.AnswerListVM;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * @Description: cs_answer_like
 * @Author: jeecg-boot
 * @Date:   2022-09-03
 * @Version: V1.0
 */
@Service
public class CsAnswerLikeServiceImpl extends ServiceImpl<CsAnswerLikeMapper, CsAnswerLike> implements ICsAnswerLikeService {
    @Autowired
    CsAnswerLikeMapper csAnswerLikeMapper;

    @Override
    public Boolean setLike(String userId, String qaId) {
        QueryWrapper<CsAnswerLike> csAnswerLikeQueryWrapper = new QueryWrapper<>();
        csAnswerLikeQueryWrapper.eq("user_id",userId).eq("qa_id",qaId);
        if(csAnswerLikeMapper.exists(csAnswerLikeQueryWrapper)){
            return false;
        }else {
            CsAnswerLike csAnswerLike = new CsAnswerLike();
            csAnswerLike.setUserId(userId);
            csAnswerLike.setQaId(qaId);
            csAnswerLikeMapper.insert(csAnswerLike);
            return true;
        }
    }

    @Override
    public Boolean cancelLike(String userId, String qaId) {
        QueryWrapper<CsAnswerLike> csAnswerLikeQueryWrapper = new QueryWrapper<>();
        csAnswerLikeQueryWrapper.eq("user_id",userId).eq("qa_id",qaId);
        if(csAnswerLikeMapper.exists(csAnswerLikeQueryWrapper)){
            csAnswerLikeMapper.delete(csAnswerLikeQueryWrapper);
            return true;
        }else {
            return false;
        }
    }
}
